﻿using System.Xml;

using pt = System.UInt32;

namespace RDLC
{  
   public class PageHeaderFooter
   {
      private readonly bool _IsHeader;

      public PageHeaderFooter(bool isHeader)
      {
         _IsHeader = isHeader;
      }

      public pt? Height
      {
         get { return _Height; }
         set
         {
            if(!_Height.HasValue)
               _Height = new pt();
            _Height = value;
         }
      }
      private pt? _Height;
      public bool? PrintOnFirstPage;
      public bool? PrintOnLastPage;

      public RDLReportItems ReportItems = new RDLReportItems();
      public HeaderFooterStyle Style;

      public void Write(XmlTextWriter writer)
      {
         writer.WriteStartElement(_IsHeader? "PageHeader" : "PageFooter");

         if(PrintOnFirstPage.HasValue)
            writer.WriteElementString("PrintOnFirstPage", PrintOnFirstPage.Value.ToString().ToLower());
         if(PrintOnLastPage.HasValue)
            writer.WriteElementString("PrintOnLastPage", PrintOnLastPage.Value.ToString().ToLower());

         Style.Write(writer);

         ReportItems.Write(writer);

         if(Height.HasValue)
            writer.WriteElementString("Height", Height + "pt");

         writer.WriteEndElement(); // PageHeader / PageFooter
      }
   }

   public class HeaderFooterStyle : RectangleStyle
   {
      public HeaderFooterStyle()
      {

      }

      public HeaderFooterStyle(RDLBorderColor borderColor, RDLBorderStyle borderStyle, RDLBorderWidth borderWidth)
         : base(borderColor, borderStyle, borderWidth)
      {
      }
   }
}